package com.san.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @auoter:jackh
 */
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    HandlerArgumentResolver handlerArgumentResolver;
    @Autowired
    AccessLimitintercepter accessLimitintercepter;
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(handlerArgumentResolver);
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(accessLimitintercepter);
    }
    /**
     * 约定大于配置正常来讲的话没有写配置文件就是去默认的/**（static）下面去找你的配置文件
     * 但是你写了配置文件就默认来这里找找不到的话，就会报错
     * @param registry
     */

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        String filePath = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\img\\";
        System.out.println(filePath);
    }
}
